package com.rfid.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import com.rfid.domain.RfidCategory;
import com.rfid.domain.VO.HouseChildVO;
import com.rfid.mapper.RfidCategoryMapper;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.rfid.mapper.RfidHouseChildMapper;
import com.rfid.domain.RfidHouseChild;
import com.rfid.service.IRfidHouseChildService;

/**
 * 仓库分区信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-12-28
 */
@Service
public class RfidHouseChildServiceImpl implements IRfidHouseChildService 
{
    @Autowired
    private RfidHouseChildMapper rfidHouseChildMapper;


    @Autowired
    private SysUserMapper userMapper;

    @Autowired
    private RfidCategoryMapper rfidCategoryMapper;
    /**
     * 查询仓库分区信息
     * 
     * @param id 仓库分区信息主键
     * @return 仓库分区信息
     */
    @Override
    public RfidHouseChild selectRfidHouseChildById(Long id)
    {
        return rfidHouseChildMapper.selectRfidHouseChildById(id);
    }

    @Override
    public List<RfidHouseChild> selectRfidHouseChildList(RfidHouseChild rfidHouseChild) {
        return rfidHouseChildMapper.selectRfidHouseChildList(rfidHouseChild);
    }

    /**
     * 查询仓库分区信息列表
     *
     * @param rfidHouseChild 仓库分区信息
     * @return 仓库分区信息
     */
    @Override
    public List<HouseChildVO> selectHouseChildVOList(RfidHouseChild rfidHouseChild)
    {
        List<RfidHouseChild> rfidHouseChildren = rfidHouseChildMapper.selectRfidHouseChildList(rfidHouseChild);
        //用户列表
        List<SysUser> users=userMapper.selectUserNameList();

        List<HouseChildVO> newList=new ArrayList<>();
        for (RfidHouseChild chid: rfidHouseChildren){
            for (SysUser user: users){
                if (Objects.equals(chid.getLeader(), user.getUserId())){
                    HouseChildVO ChildVO=new HouseChildVO(chid,user.getNickName());
                    String name = rfidCategoryMapper.selectRfidCategoryById(chid.getCategory()).getName();
                    ChildVO.setCategoryName(name);
                    Long id = chid.getId();
                    Integer integer = rfidHouseChildMapper.selectUsrHouseChildById(id);
                    ChildVO.setUsr(integer);
                    newList.add(ChildVO);
                }
            }
        }





        return newList;
    }

    /**
     * 新增仓库分区信息
     * 
     * @param rfidHouseChild 仓库分区信息
     * @return 结果
     */
    @Override
    public int insertRfidHouseChild(RfidHouseChild rfidHouseChild)
    {
        return rfidHouseChildMapper.insertRfidHouseChild(rfidHouseChild);
    }

    /**
     * 修改仓库分区信息
     * 
     * @param rfidHouseChild 仓库分区信息
     * @return 结果
     */
    @Override
    public int updateRfidHouseChild(RfidHouseChild rfidHouseChild)
    {
        return rfidHouseChildMapper.updateRfidHouseChild(rfidHouseChild);
    }

    /**
     * 批量删除仓库分区信息
     * 
     * @param ids 需要删除的仓库分区信息主键
     * @return 结果
     */
    @Override
    public int deleteRfidHouseChildByIds(Long[] ids)
    {
        return rfidHouseChildMapper.deleteRfidHouseChildByIds(ids);
    }

    /**
     * 删除仓库分区信息信息
     * 
     * @param id 仓库分区信息主键
     * @return 结果
     */
    @Override
    public int deleteRfidHouseChildById(Long id)
    {
        return rfidHouseChildMapper.deleteRfidHouseChildById(id);
    }
}
